﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GameControls.GeneralObjects
{
    public struct RectF
    {
        #region Constants
        #endregion

        #region Properties
        public float X;
        public float Y;
        public float Width;
        public float Height;

        public float Left
        {
            get { return X; }
        }

        public float Right
        {
            get { return X + Width; }
        }

        public float Top
        {
            get { return Y; }
        }

        public float Bottom
        {
            get { return Y + Height; }
        }

        public Vector2F BottomLeft
        {
            get { return new Vector2F(Left, Bottom); }
        }

        public Vector2F BottomRight
        {
            get { return new Vector2F(Right, Bottom); }
        }

        public Vector2F TopLeft
        {
            get { return new Vector2F(Left, Top); }
        }

        public Vector2F TopRight
        {
            get { return new Vector2F(Right, Top); }
        }
        #endregion

        #region Events
        #endregion

        #region Constructors
        public RectF(
            float pX,
            float pY,
            float pWidth,
            float pHeight)
        {
            X = pX;
            Y = pY;
            Width = pWidth;
            Height = pHeight;
        }
        #endregion

        #region Overriden Methods
        #endregion

        #region Methods
        public static RectF Intersect(RectF pRect1, RectF pRect2)
        {
            float l1 = pRect1.Left;
            float r1 = pRect1.Right;
            float t1 = pRect1.Top;
            float b1 = pRect1.Bottom;

            float l2 = pRect2.Left;
            float r2 = pRect2.Right;
            float t2 = pRect2.Top;
            float b2 = pRect2.Bottom;

            float l = Math.Max(l1, l2);
            float r = Math.Min(r1, r2);
            float t = Math.Max(t1, t2);
            float b = Math.Min(b1, b2);

            if (l < r && t < b)
            {
                return new RectF(l, t, r - l, b - t);
            }
            else
            {
                return new RectF();
            }
        }

        public static bool Contains(Vector2F pPoint)
        {
            return Contains(pPoint.X, pPoint.Y);
        }

        public static bool Contains(float pX, float pY)
        {
        }
        #endregion

        #region Event Handlers
        #endregion

        #region Inner Classes
        #endregion
    }
}